package worker

import (
	"encoding/json"
	"io/ioutil"
)

//程序配置
type Config struct {
	ApiReadTimeout     int      `json:"ApiReadTimeout"`
	ApiWriteTimeout    int      `json:"ApiWriteTimeout"`
	ZKEndPoint         []string `json:"ZKEndPoint"`
	ZKConnectTimeout   int      `json:"ZKConnectTimeout"`
	ExecPath           string   `json:"ExecPath"`
	LockTimeout        int      `json:"LockTimeout"`
	LockPath           string   `json:"LockPath"`
	LockType           string   `json:"LockType"`
	DbUrl              string   `json:"DbUrl"`
	DbConnectTimeout   int      `json:"DbConnectTimeout"`
	DbType             string   `json:"DbType"`
	DbName             string   `json:"DbName"`
	TableName          string   `json:"TableName"`
	QueueSize          int      `json:"QueueSize"`
	LogBatchSize       int      `json:"LogBatchSize"`
	LogCommitDelayTime int      `json:"LogCommitDelayTime"`
	LogRetryTime       int      `json:"LogRetryTime"`
	KafkaAcks          int16    `json:"KafkaAcks"`
	KafkaTopics        string   `json:"KafkaTopics"`
	KafkaPartitioner   int      `json:"KafkaPartitioner"`
	KafkaTimeout       int      `json:"KafkaTimeout"`
	KafkaBrokers       string   `json:"KafkaBrokers"`
}

//单例模式
var (
	G_Config *Config
)

func InitConfig(filename string) (err error) {
	var (
		content []byte
		conf    Config
	)
	//读取文件
	if content, err = ioutil.ReadFile(filename); err != nil {
		return err
	}
	//json的反序列表
	if err = json.Unmarshal(content, &conf); err != nil {
		return err
	}
	G_Config = &conf
	return nil

}
